<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>ArNetworking: robotUpdateExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">ArNetworking
   &#160;<span id="projectnumber">dev20161014</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('robotUpdateExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">robotUpdateExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Client that monitors status, mode and other information from a server.This example shows how to use <a class="el" href="classArClientHandlerRobotUpdate.html" title="Receives robot &quot;update&quot; responses from server and stores them. ">ArClientHandlerRobotUpdate</a> to receive updates on essential robot state data: position, speed, current server mode and status strings, etc. You can use this to detect when the server switches modes, or its status changes such as arnlServer arriving at a goal (or failing), etc. See <a class="el" href="RemoteRequestAPI.html">ArNetworking Remote Request API List</a> in the ArNetworking API reference documentation (or docs/RemoteRequestAPI.html) for a list of mode and status names, as well as ARNL or MOGS documentation if you are using ARNL or MOGS.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="ArNetworking_8h.html">ArNetworking.h</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="ArClientHandlerRobotUpdate_8h.html">ArClientHandlerRobotUpdate.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> <a name="a0"></a><a class="code" href="robotUpdateExample_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">  <a name="a1"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a2"></a><a class="code" href="classArClientBase.html">ArClientBase</a> <a name="a3"></a><a class="code" href="changeMapOnServer_8cpp.html#afe594bfb305907ae82f259409cc214cb">client</a>;</div><div class="line">  <a name="_a4"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line"></div><div class="line">  <span class="comment">/* This will be used to connect our client to the server. </span></div><div class="line"><span class="comment">   * It will get the hostname from the -host command line argument: */</span></div><div class="line">  <a name="_a5"></a><a class="code" href="classArClientSimpleConnector.html">ArClientSimpleConnector</a> clientConnector(&amp;parser);</div><div class="line"></div><div class="line">  parser.<a name="a6"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line"></div><div class="line">  <span class="comment">/* Check for -host, -help, ARIA arguments, and unhandled arguments: */</span></div><div class="line">  <span class="keywordflow">if</span> (!<a name="a7"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || !parser.<a name="a8"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">  {</div><div class="line">    <a name="a9"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a name="a10"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  }</div><div class="line"></div><div class="line">  </div><div class="line">  <span class="comment">/* Connect our client object to the remote server: */</span></div><div class="line">  <span class="keywordflow">if</span> (!clientConnector.<a name="a11"></a><a class="code" href="classArClientSimpleConnector.html#af4c6ca707c6c0f039eeb3a2a092a8160">connectClient</a>(&amp;client))</div><div class="line">  {</div><div class="line">    <span class="keywordflow">if</span> (client.<a name="a12"></a><a class="code" href="classArClientBase.html#ac8c0a3fa78872df34204b9a1aca53ddd">wasRejected</a>())</div><div class="line">      printf(<span class="stringliteral">&quot;Server &#39;%s&#39; rejected connection, exiting\n&quot;</span>, client.<a name="a13"></a><a class="code" href="classArClientBase.html#a1c10f8408523e85a6d891d0331fa6259">getHost</a>());</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">      printf(<span class="stringliteral">&quot;Could not connect to server &#39;%s&#39;, exiting\n&quot;</span>, client.<a class="code" href="classArClientBase.html#a1c10f8408523e85a6d891d0331fa6259">getHost</a>());</div><div class="line">    <a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">  } </div><div class="line"></div><div class="line">  printf(<span class="stringliteral">&quot;Connected to server.\n&quot;</span>);</div><div class="line"></div><div class="line">  client.<a name="a14"></a><a class="code" href="classArClientBase.html#a9d362e67fded3e8c36f120663c7f66cd">setRobotName</a>(client.<a class="code" href="classArClientBase.html#a1c10f8408523e85a6d891d0331fa6259">getHost</a>()); <span class="comment">// include server name in log messages</span></div><div class="line"></div><div class="line">  client.<a name="a15"></a><a class="code" href="classArClientBase.html#a778c406a8eda15109afda20521acf502">runAsync</a>();</div><div class="line"></div><div class="line"> </div><div class="line">  <a name="_a16"></a><a class="code" href="classArClientHandlerRobotUpdate.html">ArClientHandlerRobotUpdate</a> updates(&amp;client);</div><div class="line">  updates.<a name="a17"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a308497682f0b294307f76b3738509c48">requestUpdates</a>();</div><div class="line"></div><div class="line">  <span class="keywordflow">while</span> (client.<a name="a18"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classArThread.html#a05333f5f05022f42ab46a6dd8a8f1958">getRunningWithLock</a>())</div><div class="line">  {</div><div class="line">    updates.<a name="a19"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a7a7cf7df29cbfe92c0e5e590705f4e68">lock</a>();</div><div class="line">    printf(<span class="stringliteral">&quot;Mode:%s  Status:%s  Pos:%.0f,%.0f,%.0f  Vel:%.0f,%.0f,%.0f  Bat:%.1f  \r&quot;</span>,</div><div class="line">                updates.<a name="a20"></a><a class="code" href="classArClientHandlerRobotUpdate.html#ab5a2424b2d503498d15181ec894a6837">getMode</a>(),</div><div class="line">                updates.<a name="a21"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a7c2641bf77077aceb4e60988b41b4653">getStatus</a>(),</div><div class="line">                updates.<a name="a22"></a><a class="code" href="classArClientHandlerRobotUpdate.html#aa8bddfe447a9e409085a6f679d7e961a">getX</a>(), updates.<a name="a23"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a45972dbed0a0a76d41c65ec3ed8174ec">getY</a>(), updates.<a name="a24"></a><a class="code" href="classArClientHandlerRobotUpdate.html#af4a9df940976c360a684f48b613b7d93">getTh</a>(),</div><div class="line">                updates.<a name="a25"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a5e1e34e06e0daad656186d24081ac05b">getVel</a>(), updates.<a name="a26"></a><a class="code" href="classArClientHandlerRobotUpdate.html#abcdee791aeed3e74ff88bbca5a1cb495">getLatVel</a>(), updates.<a name="a27"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a13a63841f9e9188e2ab1bf6fe0ed5a3c">getRotVel</a>(),</div><div class="line">                updates.<a name="a28"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a42a17bf8772a89f2a2c3f64ec823e927">getVoltage</a>()</div><div class="line">        );</div><div class="line">        updates.<a name="a29"></a><a class="code" href="classArClientHandlerRobotUpdate.html#a2b2e2dbf3cd1fdc44cc93b4a37a1e339">unlock</a>();</div><div class="line">    <a name="a30"></a><a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/group__easy.html#ga4dfb878a3f9123b8dd96ae05b2fd94cb">ArUtil::sleep</a>(1000);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">/* The client stopped running, due to disconnection from the server, general</span></div><div class="line"><span class="comment">   * Aria shutdown, or some other reason. */</span></div><div class="line">  client.<a name="a31"></a><a class="code" href="classArClientBase.html#ad260e1e7127e1f4116c0feca12febe7d">disconnect</a>();</div><div class="line">  <a class="codeRef" doxygen="/home/reed/amrsw/Aria/docs/Aria.tag:../../docs/" href="../../docs/classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
